package com.yq.design.singleton.inner;

/**
 * @ClassName innerSingleton
 * @Description 静态内部类
 * @Author yaoqiang
 * @Date 2021/3/8 17:41
 * @Version 1.0
 */
public class Singleton {
    //私有的静态属性
    private static volatile Singleton instance;

    //构造器私有化
    private Singleton() {
    }

    //私有一个静态内部类，里面返回一个INSTANCE=new Singleton()
    private static class SingletonInstance {
        private static final Singleton INSTANCE = new Singleton();
    }

    // ，返回私有内部类中new Singleton();
    public static synchronized Singleton getInstance() {
        return SingletonInstance.INSTANCE;
    }
}
